package com.chaos.controller;/*
 * Date: 2023/10/19 9:24 PM
 * Function():
 * Author: Chao
 */

import com.chaos.response.ResponseResult;
import com.chaos.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
@RequestMapping("/user")
@CrossOrigin
@Api(tags = "用户接口")
public class UserController {

    @Autowired
    UserService  userService;

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    @ApiOperation(value = "登陆测试" )
    public ResponseResult selectByUsername(@RequestParam(value = "username",  defaultValue = "admin",required = false) String username,
                                           @RequestParam(value = "password",required = false) String password) {
        ResponseResult re = new ResponseResult();
        String token = "admin-token";
        if (password.equals(userService.selectByUsername(username).getPassword())){
            re.setCode(200);
            re.setMessage("Login Success");
            HashMap<Object, Object> a = new HashMap<>();
            a.put("token",token);
            re.setObject(a);
        } else {
            re.setCode(300);
            re.setMessage("Login failure");
        }
        return re;
    }
}
